package com.tengju.bff.interfaces.covercharge.controller.portal;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.idanchuang.component.base.JsonResult;
import com.tengju.bff.interfaces.covercharge.constant.CoverChargeEnum;
import com.tengju.bff.interfaces.covercharge.constant.CoverChargeErrorCode;
import com.tengju.bff.interfaces.covercharge.entity.po.ServiceSign;
import com.tengju.bff.interfaces.covercharge.entity.vo.*;
import com.tengju.bff.interfaces.covercharge.service.*;
import com.tengju.bff.interfaces.covercharge.util.UserUtils;
import com.tengju.bff.interfaces.shared.ApiResponse;
import com.zoi7.component.core.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 提现申请记录相关
 *
 * @author fwy
 *
 */
@Controller
@Slf4j
@RequestMapping("/api/withdrawRecord")
@Api(value = "withdrawRecord", tags = "提现审批记录")
public class WithdrawRecordController {

    @Autowired
    private IWithdrawRecodService withdrawRecodService;

    @GetMapping("/list")
    @ApiOperation(value = "获取申请记录列表",notes = "获取申请记录列表")
    @ResponseBody
    public ApiResponse<WithdrawApplyVo> getWithdrawList(HttpServletRequest request){
        //获取用户Id
        Integer idCode = UserUtils.getIdCode(request);
        WithdrawApplyVo applyVo = withdrawRecodService.getWithdrawList(idCode, UserUtils.getPlatformCode(request));
        return ApiResponse.newSuccess(applyVo);
    }

    @GetMapping("/recordDetail")
    @ApiOperation(value = "获取申请记录详情",notes = "获取申请记录详情")
    @ResponseBody
    public ApiResponse<RecordDetail> recordDetail(HttpServletRequest request, String identity , Integer recordId){
        //获取用户Id
        //Integer idCode = UserUtils.getIdCode(request);
        RecordDetail recordDetail = withdrawRecodService.getRecordDetail(identity,recordId);
        return ApiResponse.newSuccess(recordDetail);
    }

    @GetMapping("/getUpdateReasonStatus")
    @ApiOperation(value = "获取DT端是否有修改申请记录状态",notes = "获取DT端是否有修改申请记录状态")
    @ResponseBody
    public ApiResponse<?> getUpdateReasonStatus(HttpServletRequest request){
        try {
            //获取用户Id
            Integer idCode = UserUtils.getIdCode(request);
            return ApiResponse.newSuccess(withdrawRecodService.getUpdateReasonStatus(idCode));
        } catch (Exception e) {
            log.error("getUpdateReasonStatus error", e);
            return ApiResponse.newFailure(CoverChargeErrorCode.SYS_ERROR.getCode(), "获取是否有修改申请记录状态失败");
        }
    }
}
